//
//  RequestCell.m
//  SenMo
//
//  Created by ZengYuan on 15/12/31.
//  Copyright © 2015年 ZengYuan. All rights reserved.
//

#import "RequestCell.h"

@implementation RequestCell


+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"RequestCell";
    RequestCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell=[[[NSBundle mainBundle] loadNibNamed:@"RequestCell" owner:self options:nil] objectAtIndex:0];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
    }
    
    return  cell;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)tapAgree:(id)sender {
    self.tapBlock();
}

-(void)setRequestUnit:(RequestUnit *)_arequestUnit{
    _requestUnit = _arequestUnit;
    
    if(_requestUnit.hasAgree){
        [self.agreeBtn setTitle:@"已同意" forState:UIControlStateNormal];
        [self.agreeBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        self.agreeBtn.userInteractionEnabled=NO;
    }else{
        [self.agreeBtn setTitle:@"同意" forState:UIControlStateNormal];

       UIEdgeInsets imageEdgeInsets = UIEdgeInsetsMake(7, 7, 7, 7);
        UIImage *streImage = [[UIImage imageNamed:@"y_btn"] resizableImageWithCapInsets:imageEdgeInsets];

        
        [self.agreeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.agreeBtn setBackgroundImage:streImage forState:UIControlStateNormal];
        self.agreeBtn.userInteractionEnabled=YES;

    }
    
    
    self.dateLabel.text = _arequestUnit.create_time;
    
    NSMutableAttributedString*str=[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@申请观看设备%@", _arequestUnit.requester_name?_arequestUnit.requester_name:@"",_arequestUnit.requester_phoneno,_arequestUnit.deviceName]];

    //设置字体
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, str.length)];

    //设置字体颜色
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, str.length)];
    
    //设置请求人字体颜色
    [str addAttribute:NSForegroundColorAttributeName value:NAV_COLOR range:NSMakeRange(0, _arequestUnit.requester_phoneno.length+ _arequestUnit.requester_name.length)];
    
    
    //设置设备字体颜色
    [str addAttribute:NSForegroundColorAttributeName value:NAV_COLOR range:NSMakeRange(str.length - _arequestUnit.deviceName.length, _arequestUnit.deviceName.length)];
    
    self.contentLabel.attributedText = str;
}


@end
